using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;
using MeetingRoom.Data.Implementation;
using MeetingRoom.Domain;

namespace MeetingRoom.Data.Implementation
{
    public abstract class MeetingRoomQuery :
        AbstractDataAccessObject, IGetMeetingRoomsByMeetingRoomType
    {
        #region IGetMeetingRoomsByMeetingRoomType Members

        public List<MeetingRoom.Domain.MeetingRoom>
            GetMeetingRoomByMeetingRoomType(MeetingRoom.Domain.MeetingRoomType meetingRoomType)
        {
            string query =
                "select * from t_meetingroom where meetingroomtype_id = @MeetingRoomTypeId";

            SqlParameter parameter
                = new SqlParameter("@MeetingRoomTypeId", meetingRoomType.Id);

            SqlCommand command = new SqlCommand(query, (SqlConnection)this.connection);
            command.Parameters.Add(parameter);

            SqlDataReader reader = null;
            List<MeetingRoom.Domain.MeetingRoom> meetingRooms = null;

            try
            {
                reader = command.ExecuteReader();
                meetingRooms = MeetingRoomDAOSupport.GetMeetingRooms(reader);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                reader.Close();
            }

            return meetingRooms;
        }

        #endregion
    }
}
